<template>
    <el-drawer v-model="drawer" :title="title" :size="size" :close-on-click-modal="false" :destroy-on-close="destroyOnClose">
        <div class="FormDrawer">
            <div class="body">
                <slot></slot>
            </div>
            <div class="actions">
                <el-button style="border-radius: 20px;" type="primary" @click="submit" :loading="loading">{{ confirmText }}</el-button>
                <el-button style="border-radius: 20px;" type="default" @click="close">取 消</el-button>

            </div>
        </div>
    </el-drawer>
</template>
<script setup>
import {ref} from 'vue'
const drawer = ref(false)
const loading = ref(false)

const showloading=()=>loading.value=true
const hidloading=()=>loading.value=false


const props=defineProps({
    title:String,
    size:{
        type:String,
        default:"45%"
    },
    destroyOnClose:{
        type:Boolean,
        default:false
    },
    confirmText:{
        type:String,
        default:"提 交"
    }
})

const emit=defineEmits(["submit"])
//提交事件
const submit=()=>{
    emit("submit")
}


//抽屉打开
const open=()=>drawer.value=true
//抽屉关闭
const close=()=>drawer.value=false

//向父组件暴露以下几个方法
defineExpose({
    open,
    close,
    showloading,
    hidloading
})
</script>
<style scoped>
.FormDrawer{
    width: 100%;
    height: 100%;
    position: relative;
    @apply flex flex-col;
}

.FormDrawer .body{
    flex:1;
    overflow-y: auto;
}

.FormDrawer .actions{
    height: 50px;
    @apply mt-auto flex items-center;
}
</style>